package com.gimi.cloud.bbp.client.controller.product;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.gimi.cloud.bbp.dto.prod.EcProdCategoryDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.client.service.product.CategoryService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;

/**
 * Created by lixj on 2017/12/18.
 */
@RestController
@RequestMapping(value = "category")
public class CategoryController {
    private final CategoryService categoryService;

    @Autowired
    public CategoryController(CategoryService categoryService){
        this.categoryService = categoryService;
    }
    
    /** 查询商品分类列表 */
    @RequestMapping(value = "/firstGradeCategories")
    public void firstGradeList(HttpServletResponse response) {
        Response resp = new Response();
        Map<String,  Collection<EcProdCategoryDTO>> resultMap = new HashMap<>();
        //TODO 
        /*resultMap.put("firstGradeCategories", categoryService.firstGradeCategories());*/
        resultMap.put("firstGradeCategories", categoryService.getHomePageCategories());
        resp.setRes_data(resultMap);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    
    /** 查询商品分类列表 */
    @RequestMapping(value = "/secondGradeCategories")
    public void secondGradeList(@RequestBody EcProdCategoryDTO prodCategoryDTO, HttpServletResponse response) {
        Response resp = new Response();
        Map<String,  List<EcProdCategoryDTO>> resultMap = new HashMap<>();
        resultMap.put("secondGradeCategories", categoryService.secondGradeCategories(prodCategoryDTO));
        resp.setRes_data(resultMap);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }

}
